
<style>
.affix{top:10px;}
.head-style-list li,.editor-template-list li{cursor: pointer;}
</style>

		<div class="ui-portlet">
			{{template wxes/_user_wxes}}
			<ol class="breadcrumb">
			  <li><a href="/users/index"><i class="fa fa-home"></i>&nbsp;&nbsp;个人中心</a></li>
			  <li><a href="/wx_activities/mine">微配图</a></li>
			  <li class="active">新增|编辑</li>
			</ol> 
		</div>          
       <hr>

{{$this->Form->create('WxImg',array('class'=>'form-horizontal','role'=>'form'))}}
		
	<div class="tab-content">
		
			
		<div role="tabpanel" class="tab-pane active" id="chi-info">
			
						
			<div class="form-group">
				<label class="col-sm-2 control-label" for="WxImgName">配图名称</label>
				<div class="col-sm-10 controls">
					{{$this->Form->hidden('id')}}
					{{$this->Form->input('name',array('class'=>'form-control','required'=>'required', 'div'=>false,'label'=>false))}}
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-2 control-label" for="WxImgName">唯一标识</label>
				<div class="col-sm-10 controls">
					{{$this->Form->input('slug',array('class'=>'form-control','required'=>'required', 'div'=>false,'label'=>false))}}
					<p>发送配图与唯一标识开始生成配图之旅。</p>
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-2 control-label" for="WxStorefrontCoverImg">封面图片</label>
				<div class="col-sm-10 controls select">
					{{$this->Swfupload->load('coverimg',array(
					'label'=>false,'modelClass'=>'WxImg',
					'no_db'=>1,'upload_limit'=>1,
					'file_types'=> '*.jpg;*.gif;*.png;*.bmp',
					'isadmin'=>false
					))}}
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-2 control-label" for="WxImgName">输入指引</label>
				<div class="col-sm-10 controls">
					{{$this->Form->input('help_words',array('class'=>'form-control','type'=>'textarea', 'rows'=>'3', 'div'=>false,'label'=>false))}}
					<p>加入活动时，回复的提示文本，指导用户输入</p>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label" for="WxImgName">用户输入项</label>
				<div class="col-sm-12 controls form-inline">
					<table id="UserImputsTable" class="table"><tr><th>名称</th><th>类型</th><th>收到后回复内容</th><th></th></tr>

{{if is_array($this->data['WxImg']['user_inputs'])}}
	{{loop $this->data['WxImg']['user_inputs'] $k $input}}
		<tr>
			<td>{{$this->Form->input('WxImg.user_inputs.'.$k.'.name',array('type'=>'text','value'=>$input['name'],'class'=>'form-control','div'=>false,'label'=>false))}}</td>
			<td>{{$this->Form->input('WxImg.user_inputs.'.$k.'.type',array('type'=>'select','value'=>$input['type'],'default'=>'text','options'=>array('text'=>'文本消息','image'=>'图片','voice'=>'语音'),'class'=>'form-control','div'=>false,'label'=>false))}}</td>
			<td>{{$this->Form->input('WxImg.user_inputs.'.$k.'.message',array('type'=>'textarea', 'value'=>$input['message'],'rows'=>'3','class'=>'form-control','div'=>false,'label'=>false))}}</td>
			<td><i class="fa fa-plus"></i> <i class="fa fa-minus"></i> </td>
		</tr>
	{{/loop}}
	{{if empty($this->data['WxImg']['user_inputs']) }}
		<tr>
			<td>{{$this->Form->input('WxImg.user_inputs.0.name',array('type'=>'text','class'=>'form-control','div'=>false,'label'=>false))}}</td>
			<td>{{$this->Form->input('WxImg.user_inputs.0.type',array('type'=>'select','default'=>'text','options'=>array('text'=>'文本消息','image'=>'图片','voice'=>'语音'),'class'=>'form-control','div'=>false,'label'=>false))}}</td>
			<td>{{$this->Form->input('WxImg.user_inputs.0.message',array('type'=>'textarea', 'rows'=>'3','class'=>'form-control','div'=>false,'label'=>false))}}</td>
			<td><i class="fa fa-plus"></i> <i class="fa fa-minus"></i> </td>
		</tr>
	{{/if}}
{{else}}
	<tr>
		<td>{{$this->Form->input('WxImg.user_inputs.0.name',array('type'=>'text','class'=>'form-control','div'=>false,'label'=>false))}}</td>
		<td>{{$this->Form->input('WxImg.user_inputs.0.type',array('type'=>'select','default'=>'text','options'=>array('text'=>'文本消息','image'=>'图片','voice'=>'语音'),'class'=>'form-control','div'=>false,'label'=>false))}}</td>
		<td>{{$this->Form->input('WxImg.user_inputs.0.message',array('type'=>'textarea', 'rows'=>'3','class'=>'form-control','div'=>false,'label'=>false))}}</td>
		<td><i class="fa fa-plus"></i> <i class="fa fa-minus"></i> </td>
	</tr>
{{/if}}
					</table>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label" for="WxImgName">系统随机值项</label>
				<div class="col-sm-12 controls form-inline">
					<table id="RandomOptionsTable" class="table"><tr><th>名称</th><th>随机值项（每行一条值，文字有换行时，使用\n）</th><th></th></tr>
{{if is_array($this->data['WxImg']['random_options'])}}
	{{loop $this->data['WxImg']['random_options'] $rk $option}}
		<tr>
			<td>{{$this->Form->input('WxImg.random_options.'.$rk.'.name',array('type'=>'text','value'=>$option['name'],'class'=>'form-control','div'=>false,'label'=>false))}}</td>
			<td>{{$this->Form->input('WxImg.random_options.'.$rk.'.values',array('type'=>'textarea','value'=>$option['values'], 'rows'=>'3','class'=>'form-control','div'=>false,'label'=>false))}}</td>
			<td><i class="fa fa-plus"></i> <i class="fa fa-minus"></i> </td>
		</tr>
	{{/loop}}
	{{if empty($this->data['WxImg']['random_options']) }}
		<tr>
			<td>{{$this->Form->input('WxImg.random_options.0.name',array('type'=>'text','class'=>'form-control','div'=>false,'label'=>false))}}</td>
			<td>{{$this->Form->input('WxImg.random_options.0.values',array('type'=>'textarea', 'rows'=>'3','class'=>'form-control','div'=>false,'label'=>false))}}</td>
			<td><i class="fa fa-plus"></i> <i class="fa fa-minus"></i> </td>
		</tr>
	{{/if}}
{{else}}
	<tr>
		<td>{{$this->Form->input('WxImg.random_options.0.name',array('type'=>'text','class'=>'form-control','div'=>false,'label'=>false))}}</td>
		<td>{{$this->Form->input('WxImg.random_options.0.values',array('type'=>'textarea', 'rows'=>'3','class'=>'form-control','div'=>false,'label'=>false))}}</td>
		<td><i class="fa fa-plus"></i> <i class="fa fa-minus"></i> </td>
	</tr>
{{/if}}
					</table>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label" for="WxImgRuleType">配图类型</label>
				<div class="col-sm-10 controls">
					{{$this->Form->input('rule_type',array('type'=>'select','required'=>'required', 'class'=>'form-control','div'=>false,'label'=>false))}}
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label" for="WxImgRuleType">配图规则</label>
				<div class="col-sm-10 controls">
					{{$this->Form->input('rule_details',array('type'=>'textarea', 'rows'=>'3','class'=>'form-control','div'=>false,'label'=>false))}}
					<p>使用json字符串格式输入多个规则，没有时请留空</p>
				</div>
			</div>

								
			<div class="form-group">
				<p><label class="col-sm-2 control-label" for="WxImgBusinessHours">详细代码</label></p>
				<div class="col-sm-12 controls">
					{{$this->Form->input('content',array('class'=>'form-control','rows'=>'3','div'=>false,'label'=>false,))}}
				</div>
			</div>
		</div>
	</div>
	
	
	<div class="form-group">
		<label class="col-sm-2 control-label"></label>
		<div class="col-sm-10"><input class="btn btn-primary" type="submit" value="提交"></div>
	</div>
{{$this->Form->end()}}


{{$this->Html->script(array(
	'ckeditor/ckeditor.js',
	'swfupload/swfupload.js',
	'swfupload/swfupload.queue.js',
	'swfupload/swfupload.cookies.js',
	'swfupload/fileprogress.js',
	'swfupload/handlers.js',
))}}

<script>
$(function(){
	var max_item = {{$k?$k:0}};
	$(document).on('click','#UserImputsTable .fa-plus',function(){
		max_item = max_item+1;
		var tr = $(this).parents('tr:first');

		var new_tr = tr.clone();
		var html = new_tr.html();
		html = html.replace(/\[\d+\]/g,'['+max_item+']');
		new_tr.html(html);
		new_tr.insertAfter(tr);
	});

	$(document).on('click','#UserImputsTable .fa-minus',function(){
		max_item = max_item+1;

		/*if( $(this).parents('table:first').find('tr').size() == 2) {
			alert("最后一个不能删除");
			return false;
		}*/

		var tr = $(this).parents('tr:first');
		if(confirm("是否确认删除这行")) {
			tr.remove();
		}
	});

	var max_rd_item = {{$rk?$rk:0}};
	$(document).on('click','#RandomOptionsTable .fa-plus',function(){
		max_rd_item = max_rd_item+1;
		var tr = $(this).parents('tr:first');

		var new_tr = tr.clone();
		var html = new_tr.html();
		html = html.replace(/\[\d+\]/g,'['+max_rd_item+']');
		new_tr.html(html);
		new_tr.insertAfter(tr);
	});

	$(document).on('click','#RandomOptionsTable .fa-minus',function(){
		max_rd_item = max_rd_item+1;

		/*if( $(this).parents('table:first').find('tr').size() == 2) {
			alert("最后一个不能删除");
			return false;
		}*/

		var tr = $(this).parents('tr:first');
		if(confirm("是否确认删除这行")) {
			tr.remove();
		}
	});

});

var current_ckeditor_instance = null;

$(function(){

	CKEDITOR.editorConfig = function( config ){
		config.toolbar = 'FRONT';
	}
	ckeditors['WxImgContent'] = CKEDITOR.replace( 'WxImgContent',
		    {
		        customConfig : '{{$this->Html->url("/js/ckeditor/front-config.js")}}'
		    });
	ckeditors['WxImgContent'].on('focus',function(e){
		current_ckeditor_instance = e.editor;
	});
	
})

</script>
